/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.awt.Graphics;
import java.util.Timer;
import java.awt.Polygon;

public class Not extends CommonGate implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Not(Timer a, int x, int y, int pos) {
		this.myTimer = a;
		myTimer.schedule(new ActionDelay(this),0L, 200L);
		this.x = x - getWidth() / 2;
		this.y = y - getHeight() / 2;
		this.pos = pos;
	}

	public Not(Timer a) {
		this.myTimer = a;
		myTimer.schedule(new ActionDelay(this), 200L, 200L);
		this.x = 0;
		this.y = 0;
		this.pos = 0;
	}

	public void setNewValue() {

		if (inputList.size() == 0) {
			actualValue = null;
			return;
		}

		if (inputList.get(0).getValue(actualIndex) == null) {
			actualValue = null;
			return;
		}

		if (inputList.get(0).getValue(actualIndex) == 1) {
			actualValue = 0;
			return;
		}

		actualValue = 1;
		return;
	}

	public Integer compute(Integer input1) {
		if (input1 == 0)
			this.outputValue = new Integer(1);
		else
			this.outputValue = new Integer(0);
		return this.outputValue;
	}

	// down here all the methods related to the gui

	public void draw(final Graphics g) {
		int x1 = x + 30;
		int y1 = y + 20;
		int y2 = y1 + 20;

		int[] xPoints = new int[3];
		xPoints[0] = x;
		xPoints[1] = x1;
		xPoints[2] = x;
		int[] yPoints = new int[3];
		yPoints[0] = y;
		yPoints[1] = y1;
		yPoints[2] = y2;

		Polygon poly = new Polygon(xPoints, yPoints, 3);
		g.drawPolygon(poly);
		g.drawOval(x1, y1 - 5, 10, 10);
	}

}
